package com.controller;

import com.constants.Constants;
import com.entity.AllTask;
import com.tools.BaseUntil;
import com.until.TaskManag;
import javafx.fxml.FXML;
import javafx.fxml.Initializable;
import javafx.scene.control.Label;
import javafx.scene.control.TableView;
import javafx.scene.control.TextArea;
import javafx.scene.control.TextField;
import javafx.scene.text.Text;
import javafx.stage.Stage;

import java.net.URL;
import java.util.ResourceBundle;

public class TaskDitileController extends BaseUntil implements Initializable {
    public TaskDitileController() {
        //初始化时保存当前Controller实例
        Constants.controllers.put(this.getClass().getSimpleName(), this);
    }

    private AllTask ditileTask = MainController.ditileTask;

    @FXML
    private Label queryTask;
    @FXML
    private TextField id;
    @FXML
    private TextField title;
    @FXML
    private TextField info;
    @FXML
    private TextField tasktype;
    @FXML
    private TextField countpotato;
    @FXML
    private TextField countsleep;
    @FXML
    private TextField nowtype;
    @FXML
    private TextField msg;
    @FXML
    private TextField maketime;
    @FXML
    private TextField finishtime;
    MainController controller = (MainController) Constants.controllers.get(MainController.class.getSimpleName());
    public void clossWindow() {
        Stage stage = (Stage) queryTask.getScene().getWindow();
        stage.close();
        controller.showList();
    }

    public void updateInfo() {
        ditileTask.setTitle(title.getText());
        ditileTask.setNowtype(nowtype.getText());
        ditileTask.setInfo(info.getText());
        ditileTask.setMsg(msg.getText());
        TaskManag.updateTask(ditileTask);
        Stage stage = (Stage) queryTask.getScene().getWindow();
        stage.close();
        controller.showList();
    }


    @Override
    public void initialize(URL location, ResourceBundle resources) {
        showDitle();
    }

    public void showDitle() {
        id.setText(ditileTask.getId());
        title.setText(ditileTask.getTitle());
        info.setText(ditileTask.getInfo());
        tasktype.setText(ditileTask.getTasktype());
        countpotato.setText(ditileTask.getCountpotato());
        countsleep.setText(ditileTask.getCountsleep());
        nowtype.setText(ditileTask.getNowtype());
        msg.setText(ditileTask.getMsg());
        maketime.setText(ditileTask.getMaketime());
        finishtime.setText(ditileTask.getFinishtime());
    }
}
